// index.js
Page({
  data: {
    msg1: "这是一条测试数据",
    msg2: "这是一条测试数据",
    time1: "一",
    time2: "两",
    userName1: "张三",
    userName2: "李丽",
    msgList: [],

  },

  onLoad() {

  },
  onShow() {
    let that = this;
    let messageList;
    wx.request({
      url: 'http://120.79.197.164:9285/barter/post/getPostList',
      method: 'POST',
      data: {
        pageNum: 1,
        pageSize: 100,
        title: "",
        userId: wx.getStorageSync('uuid'),
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        messageList = res.data.data;
        var msgArr;
        if(messageList != null){
          for (var i = 0; i < messageList.length; i++) {
            var j = i;
            // msgArr = messageList;
            // msgArr.push(messageList[j]);
            wx.request({
              url: 'http://120.79.197.164:9285/barter/user/getUserByUserId/' + messageList[j].userId,
              method: 'GET',
              data: {},
              header: {
                'content-type': 'application/json' // 默认值
              },
              success(res) {
                // console.log(res.data.data);
                // console.log(messageList[j]);

                messageList[j].userName = res.data.data.userName;
                messageList[j].sex = res.data.data.sex;
                msgArr = messageList;
                // console.log(msgArr[j]);
                // console.log(j);
                // msgArr.push(messageList[j]);

                that.setData({
                  msgList: msgArr,
                });
              }

            });
          }
        }

      }

    });
  }
})